package com.tools.cleanmaster.model.db;

import android.database.Cursor;

import com.tools.cleanmaster.model.db.annotations.TrashDBAnnotation;
import com.tools.cleanmaster.model.db.annotations.Type;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class WhiteListBean {
    @TrashDBAnnotation(name = "a", type = Type.IntData)
    public int id;
    @TrashDBAnnotation(name = "b", type = Type.StringData)
    public String pkgName;
    @TrashDBAnnotation(name = "c", type = Type.StringData)
    public String filePath;
    //（1 缓存,2残留,4系统, 8 广告）
    @TrashDBAnnotation(name = "d", type = Type.IntData)
    public int type;

    public WhiteListBean() {

    }

    public static List<WhiteListBean> fromCursor(Cursor cursor) {
        if (cursor == null || cursor.getCount() == 0) {
            return Collections.emptyList();
        }

        final int idIndex = cursor.getColumnIndexOrThrow("a");
        final int pkgNameIndex = cursor.getColumnIndexOrThrow("b");
        final int filePathIndex = cursor.getColumnIndexOrThrow("c");
        final int typeIndex = cursor.getColumnIndexOrThrow("d");

        ArrayList<WhiteListBean> beans = new ArrayList<WhiteListBean>(cursor.getCount());

        while (cursor.moveToNext()) {
            WhiteListBean bean = new WhiteListBean();
            bean.id = cursor.getInt(idIndex);
            bean.pkgName = cursor.getString(pkgNameIndex);
            bean.filePath = cursor.getString(filePathIndex);
            bean.type = cursor.getInt(typeIndex);

            beans.add(bean);
        }

        return beans;
    }
}
